package com.moyou.weichat.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.moyou.weichat.R;

/**
 * Created by Administrator on 2017/2/8 0008.
 */

public class MenuView extends RelativeLayout implements View.OnClickListener {

    private View view;

    private Context context;

    private TextView cameraBtn, videoBtn, chatRadBtn, chat_menu_collect;

    private MenuCall menuCall;

    private TextView MapBtn;

    private TextView friendBtn;

    private TextView chat_menu_openVideo, chat_menu_openVoice, chat_menu_card;

    private int chatType;


    public void setMenuCall(MenuCall menuCall) {
        this.menuCall = menuCall;
    }

    public MenuView(Context mContext, int type) {
        super(mContext);
        this.chatType = type;
        context = mContext;
    }

    public void initView() {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        if (view == null) {
            view = inflater.inflate(R.layout.item_chat_menu, null);
            chat_menu_card = (TextView) view.findViewById(R.id.chat_menu_card);
            chat_menu_collect = (TextView) view.findViewById(R.id.chat_menu_collect);
            cameraBtn = (TextView) view.findViewById(R.id.chat_menu_camera);
            videoBtn = (TextView) view.findViewById(R.id.chat_menu_video);
            MapBtn = (TextView) view.findViewById(R.id.map_btn);
            chatRadBtn = (TextView) view.findViewById(R.id.chat_menu_rad);
            friendBtn = (TextView) view.findViewById(R.id.chat_menu_friend);
            chat_menu_openVideo = (TextView) view.findViewById(R.id.chat_menu_openVideo);
            chat_menu_openVoice = (TextView) view.findViewById(R.id.chat_menu_openVoice);
        }
        if (chatType == 0) {
            chat_menu_openVideo.setVisibility(VISIBLE);
            chat_menu_openVoice.setVisibility(VISIBLE);
        } else {
            chat_menu_openVideo.setVisibility(GONE);
            chat_menu_openVoice.setVisibility(GONE);
        }
        LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        setLayoutParams(params);
        addView(view, params);
        chat_menu_collect.setOnClickListener(v -> menuCall.collectBtn());
        chat_menu_card.setOnClickListener(v -> menuCall.cardBtn());
        clickListener();
    }


    //聊天第二页
    public void initTwoView() {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        if (view == null) {
            view = inflater.inflate(R.layout.item_chat_menu_two, null);
            chat_menu_card = (TextView) view.findViewById(R.id.chat_menu_card);
        }
        LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        setLayoutParams(params);
        addView(view, params);
        chat_menu_card.setOnClickListener(v -> menuCall.cardBtn());
    }

    private void clickListener() {
        videoBtn.setOnClickListener(this);
        cameraBtn.setOnClickListener(this);
        MapBtn.setOnClickListener(this);
        chatRadBtn.setOnClickListener(this);
        friendBtn.setOnClickListener(this);
        chat_menu_openVoice.setOnClickListener(this);
        chat_menu_openVideo.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.chat_menu_camera:
                VideoDialog dialog = new VideoDialog(context, true);
                dialog.setImageSelectCall(new VideoDialog.ImageSelectCall() {
                    @Override
                    public void shootBtn() {
                        menuCall.cameraBtn();
                    }

                    @Override
                    public void nativePlaceBtn() {
                        menuCall.imageBtn();
                    }
                });
                break;
            case R.id.chat_menu_video:
                menuCall.videoBtn();
                break;
            case R.id.map_btn:
                menuCall.locationBtn();
                break;
            case R.id.chat_menu_rad:
                menuCall.radBtn();
                break;
            case R.id.chat_menu_friend:
                menuCall.friendBtn();
                break;
            //语音通话
            case R.id.chat_menu_openVoice:
                menuCall.voiceCommunicate();
                break;
            //视频通话
            case R.id.chat_menu_openVideo:
                menuCall.videoCommunicate();
                break;
        }
    }


    public interface MenuCall {

        void imageBtn();

        void cameraBtn();

        void videoBtn();

        void locationBtn();

        void radBtn();

        void friendBtn();

        void voiceCommunicate();

        void videoCommunicate();

        void collectBtn();

        void cardBtn();

    }

}
